package org.springblade.tms.module.demandorder.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.tms.global.enums.StationTypeEnum;
import org.springblade.tms.global.enums.TransportTypeEnum;
import org.springblade.tms.module.demandextrainfo.base.DemandExtraService;
import org.springblade.tms.module.demandextrainfo.entity.TmDemandExtraInfo;
import org.springblade.tms.module.demandextrainfo.service.ITmDemandExtraInfoService;
import org.springblade.tms.module.demandextrainfo.vo.TmDemandExtraInfoVO;
import org.springblade.tms.module.demandextrainfo.wrapper.TmDemandExtraInfoWrapper;
import org.springblade.tms.module.demandorder.base.AppDemandListService;
import org.springblade.tms.module.demandorder.base.DemandListService;
import org.springblade.tms.module.demandorder.dto.AllocatingWaybillDto;
import org.springblade.tms.module.demandorder.dto.AppDemandOrderDto;
import org.springblade.tms.module.demandorder.dto.RejectOrderDto;
import org.springblade.tms.module.demandorder.vo.DemandOrderVo;
import org.springblade.tms.module.demandorder.vo.TMDemandEventVO;
import org.springblade.tms.module.demandorder.vo.TMDemandOrderVO;
import org.springblade.tms.module.station.entity.TMStation;
import org.springblade.tms.module.station.service.IStationService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;

/**
 * @projectName: BladeX
 * @package: org.springblade.tms.module.demandorder.controller
 * @className: AppDemandListController
 * @author: yr
 * @description: app需求单接口
 * @date: 2022/3/21 10:43
 */
@RestController
@RequestMapping("demandorder/AppDemandList")
@Api(value = "app需求单-yr", tags = "app需求单接口-yr")
public class AppDemandListController {
	@Resource
	private AppDemandListService appDemandListService;
	@Resource
	private DemandListService demandListService;
	@Resource
	private DemandExtraService demandExtraService;


	/**
	 * @param appDemandOrderDto:
	 * @param query:
	 * @return R<IPage < TMDemandOrderVO>>
	 * @author yr
	 * @description 需求单列表查询
	 * @date 2022/3/16 16:12
	 */
	@GetMapping("/list")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "需求单列表查询", notes = "传入appDemandOrderDto")
	public R<IPage<TMDemandOrderVO>> list(AppDemandOrderDto appDemandOrderDto, Query query) {
		return appDemandListService.list(appDemandOrderDto, query);
	}


	/**
	 * 补全信息查看
	 */
	@GetMapping("view")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "补全信息详情", notes = "传入需求单demandId")
	public R<TmDemandExtraInfo> detail(@NotNull Long demandId) {
		return appDemandListService.detail(demandId);

	}


	/**
	 * @param rejectOrderDto:
	 * @return R
	 * @author yr
	 * @description 接单或拒单
	 * @date 2022/3/21 11:26
	 */
	@PostMapping("/rejectOrder")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "接单或拒单", notes = "传入rejectOrderDto")
	public R rejectOrder(RejectOrderDto rejectOrderDto) {
		return appDemandListService.rejectOrder(rejectOrderDto);
	}

	/**
	 * @param allocatingWaybillDto:
	 * @return null
	 * @author yr
	 * @description 分配运单
	 * @date 2022/3/21 10:45
	 */
	@PostMapping("/allocatingWaybill")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "分配运单", notes = "传入司机车辆押运员需求单id和物料id数量")
	public R allocatingWaybill(@RequestBody AllocatingWaybillDto allocatingWaybillDto) {
		return demandListService.allocatingWaybill(allocatingWaybillDto);
	}

	/**
	 * @param id:
	 * @return null
	 * @author yr
	 * @description 需求单详情
	 * @date 2022/3/17 10:45
	 */
	@GetMapping("/detail")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "需求单详情", notes = "传入demandOrderId")
	public R<DemandOrderVo> detail(Long id, Query query) {
		return demandListService.detail(id, query);
	}

	/**
	 * 需求单事件变更
	 */
	@PostMapping("/event")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "需求单事件变更")
	public R event(@RequestBody @Validated TMDemandEventVO input) {
		demandExtraService.eventChange(input);
		return R.success("成功");
	}

	/**
	 * @param tmId:
	 * @return null
	 * @author yr
	 * @description 司机车辆押运员列表
	 * @date 2022/3/17 10:45
	 */
	@GetMapping("/driverCarEscortList")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "司机车辆押运员坦克罐列表", notes = "传入承运商编码")
	public R<Object> driverCarEscortList(@ApiParam("承运商编码") String tmId, @ApiParam("需求单id") Long id, @ApiParam("运输单id") Long transportId, Query query) {
		return demandListService.driverCarEscortList(tmId, id, transportId, query);
	}


	/**
	 * 补全信息
	 */
	@PostMapping("fill")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "补全信息", notes = "id不用传")
	public R<Long> fill(@RequestBody @Validated(TmDemandExtraInfo.FILL_INFO.class) TmDemandExtraInfoVO input) {
		return R.data(demandExtraService.fillDemandExtra(input));
	}

}
